#include "TextElement.h"

TextElement::TextElement(PaintArea* parent, QPoint& position) : QLineEdit(parent)
{
	currentPosition = position;
	ourImage = parent;
	ConnectionClass* connection = new ConnectionClass();
	textEdit = new QLineEdit();
	//textEdit->move(position);
	
	//this->textEdit->close();
	//connect (this->textEdit, SIGNAL(focusOutEvent(QFocusEvent)), this->textEdit, SLOT(handleReturnPressed()));

	//connect(this->textEdit, SIGNAL(on_lineEditSubmit()), connection, SLOT(showTextDisplay(QString)));
	//QObject::connect(this->textEdit, SIGNAL(this->textEdit->returnPressed()), this->textEdit, SLOT(on_lineEditSubmit()));
}

void TextElement::handleReturnPressed()
{
	this->textEdit->close();
    //emit(on_lineEditSubmit());
}

void TextElement::returnPressed()
{
	this->textEdit->close();
    //emit(on_lineEditSubmit());
}

void TextElement::focusOutEvent(QFocusEvent* e)
{
	this->textEdit->close();
}

TextElement::TextElement()
{
}

TextElement::~TextElement()
{
}

void TextElement::showTextBox()
{
	this->textEdit->show();
}

void TextElement::closeTextBox()
{
	this->textEdit->close();
}

QString TextElement::onLineEditSubmit()
{
	textEdit->close();
	return textEdit->text();
}
void TextElement::keyPressEvent(QKeyEvent *event)
{
	if (event->key() == Qt::Key_Escape) {  
		this->textEdit->close();
	}
} 

